package pl.koziolekweb.szkola.CEAbstrakcyjne;

// CE-Abstrakcyjne/Figura.java
 
abstract class Figura implements Comparable<Figura> {

    abstract public double getPole();
    abstract public double getObwod();

    static public Figura getFigMaxPole(Figura[] figs) {
        double maxarea = 0;
        Figura maxfig  = null;
        for (Figura f : figs) {
            double area = f.getPole();
            if (area > maxarea) {
                maxarea = area;
                maxfig  = f;
            }
        }
        return maxfig;
    }

    @Override
    public String toString() {
        return " pole: "
              + String.format("%6.3f",getPole())
              + "; obwod: "
              + String.format("%6.3f",getObwod());
    }

    public int compareTo(Figura f) {
        double diff = getObwod() - f.getObwod();
        if      (diff < 0) return -1;
        else if (diff > 0) return +1;
        else               return 0;
    }
}
